//
//  WJAlertController.m
//  JerryIos
//
//  Created by 王军 on 2018/2/11.
//  Copyright © 2018年 王军. All rights reserved.
//

#import "WJAlertController.h"
#import "SettingModelView.h"
#import "ShareView.h"
#import "UIView+TYAlertView.h"

@interface WJAlertController ()

@end

@implementation WJAlertController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (IBAction)AlertViewInControllerClick:(id)sender {
    //定义一个AlertView
    TYAlertView *alertView = [TYAlertView alertViewWithTitle:@"TYAlertView"
                                                     message:@"This is a message, the alert view containt text and textfiled. "];
    //定义AlertView上的取消按钮
    [alertView addAction:[TYAlertAction actionWithTitle:@"取消"
                                                  style:TYAlertActionStyleCancel
                                                handler:^(TYAlertAction *action) {
        NSLog(@"%@",action.title);
    }]];
    //定义AlertView上的确定按钮
    __typeof (alertView) __weak weakAlertView = alertView;   // 弱引用alertView 否则 会循环引用
    [alertView addAction:[TYAlertAction actionWithTitle:@"确定"
                                                  style:TYAlertActionStyleDestructive
                                                handler:^(TYAlertAction *action) {
        NSLog(@"%@",action.title);
        for (UITextField *textField in weakAlertView.textFieldArray) {
            NSLog(@"%@",textField.text);
        }
    }]];
    //定义AlertView上的账号输入框
    [alertView addTextFieldWithConfigurationHandler:^(UITextField *textField) {
        textField.placeholder = @"请输入账号";
    }];
    //定义AlertView上的密码输入框
    [alertView addTextFieldWithConfigurationHandler:^(UITextField *textField) {
        textField.placeholder = @"请输入密码";
    }];
    
    //第一种显示方式
    TYAlertController *alertController = [TYAlertController alertControllerWithAlertView:alertView
                                                                          preferredStyle:TYAlertControllerStyleAlert];
    //以下为弹出框的生命周期方法
    [alertController setViewWillShowHandler:^(UIView *alertView) {
        NSLog(@"ViewWillShow");
    }];
    [alertController setViewDidShowHandler:^(UIView *alertView) {
        NSLog(@"ViewDidShow");
    }];
    [alertController setViewWillHideHandler:^(UIView *alertView) {
        NSLog(@"ViewWillHide");
    }];
    [alertController setViewDidHideHandler:^(UIView *alertView) {
        NSLog(@"ViewDidHide");
    }];
    [alertController setDismissComplete:^{
        NSLog(@"DismissComplete");
    }];
    //显示弹出框
    //alertController.alertViewOriginY = 60;
    [self presentViewController:alertController animated:YES completion:nil];
    
    //第二种显示方式
    //[alertView showInController:self preferredStyle:TYAlertControllerStyleAlert];
}

- (IBAction)dropdownAnimationClick:(id)sender {
    TYAlertView *alertView = [TYAlertView alertViewWithTitle:@"TYAlertView"
                                                     message:@"This is a message, the alert view containt dropdwon animation. "];
    
    [alertView addAction:[TYAlertAction actionWithTitle:@"取消"
                                                  style:TYAlertActionStyleCancel
                                                handler:^(TYAlertAction *action) {
        NSLog(@"%@",action.title);
    }]];
    
    //第一种显示方式
    TYAlertController *alertController = [TYAlertController alertControllerWithAlertView:alertView
                                                                          preferredStyle:TYAlertControllerStyleAlert
                                                                     transitionAnimation:TYAlertTransitionAnimationDropDown];
    [self presentViewController:alertController animated:YES completion:nil];
    
    //第二种显示方式（use UIView Category）
    //[alertView showInController:self preferredStyle:TYAlertControllerStyleAlert];
}

- (IBAction)actionSheetClick:(id)sender {
    TYAlertView *alertView = [TYAlertView alertViewWithTitle:@"TYAlertView"
                                                     message:@"This is a message, the alert view style is actionsheet. "];
    [alertView addAction:[TYAlertAction actionWithTitle:@"默认2"
                                                  style:TYAlertActionStyleDefault
                                                handler:^(TYAlertAction *action) {
        NSLog(@"%@",action.title);
    }]];
    [alertView addAction:[TYAlertAction actionWithTitle:@"默认1"
                                                  style:TYAlertActionStyleDefault
                                                handler:^(TYAlertAction *action) {
        NSLog(@"%@",action.title);
    }]];
    [alertView addAction:[TYAlertAction actionWithTitle:@"删除"
                                                  style:TYAlertActionStyleDestructive
                                                handler:^(TYAlertAction *action) {
        NSLog(@"%@",action.title);
    }]];
    [alertView addAction:[TYAlertAction actionWithTitle:@"取消"
                                                  style:TYAlertActionStyleCancel
                                                handler:^(TYAlertAction *action) {
        NSLog(@"%@",action.title);
    }]];
    
    //第一种显示方式
    TYAlertController *alertController = [TYAlertController alertControllerWithAlertView:alertView
                                                                          preferredStyle:TYAlertControllerStyleActionSheet];
    [self presentViewController:alertController animated:YES completion:nil];
}

- (IBAction)customActionSheetClick:(id)sender {
    //xib方式创建AlertView
    SettingModelView *settingModelView = [SettingModelView createViewFromNib];
    
    //第一种显示方式（use UIView Category）
    //[settingModelView showInController:self preferredStyle:TYAlertControllerStyleActionSheet backgoundTapDismissEnable:YES];
    
    //第二种显示方式
    TYAlertController *alertController = [TYAlertController alertControllerWithAlertView:settingModelView
                                                                          preferredStyle:TYAlertControllerStyleActionSheet];
    alertController.backgoundTapDismissEnable = YES;
    [self presentViewController:alertController animated:YES completion:nil];
}

- (IBAction)AlertViewInWindow:(id)sender {
    //定义一个AlertView
    TYAlertView *alertView = [TYAlertView alertViewWithTitle:@"TYAlertView"
                                                     message:@"A message should be a short, but it can support long message"];
    //定义AlertView上的取消按钮
    [alertView addAction:[TYAlertAction actionWithTitle:@"取消"
                                                  style:TYAlertActionStyleCancel
                                                handler:^(TYAlertAction *action) {
        NSLog(@"%@",action.title);
    }]];
    //定义AlertView上的确定按钮
    [alertView addAction:[TYAlertAction actionWithTitle:@"确定"
                                                  style:TYAlertActionStyleDestructive
                                                handler:^(TYAlertAction *action) {
        NSLog(@"%@",action.title);
    }]];
    
    //第一种显示方式 ,use UIView Category
    [alertView showInWindowWithOriginY:200 backgoundTapDismissEnable:YES];
    
    //第二种显示方式
    //[TYShowAlertView showAlertViewWithView:alertView originY:200 backgoundTapDismissEnable:YES];
}

- (IBAction)customViewInWindow:(id)sender {
    ShareView *shareView = [ShareView createViewFromNib];
    // use UIView Category
    [shareView showInWindow];
}


@end
